<template>
	<view>
		<view class="lyzml-btn" @tap="startSearch">开始扫描</view>
		<view class="lyzml-btn" @tap="stopSearch">停止扫描</view>
		<view class="lyzml-btn" @tap="getSearchResult">获取结果</view>
		<view class="lyzml-btn" @tap="play">播放</view>
		<view class="lyzml-btn" @tap="stopVideo">停止</view>
		<view class="lyzml-btn" @tap="clearDevice">清除设备</view>
		<view class="lyzml-btn" @tap="getIPAddress">获取本机IP</view>
		<view class="device-item" v-for="(item,index) in devList" :key="index" @tap="playVideo(item)">
			{{item.ip}}--{{item.name}}
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
                devList:[]
			}
		},
		computed: {

		},
		onLoad(params) {

		},
		onShow() {

		},
		methods: {
			startSearch(){
				// uni.showToast({
				// 	title:"startSearch"
				// })
				console.log("====startSearch====",lyzmlDLNA);
				this.$lobster.lyzmlDLNA.startSearch((res)=>{
					console.log(res);
					uni.showModal({
						content:JSON.stringify(res)
					})
					//this.devList = devList;
					//console.log("====startSearch====",JSON.stringify(devList));
				});
			},
			stopSearch(){
				console.log("====stopSearch====");
				this.$lobster.lyzmlDLNA.stopSearch();
			},
			getSearchResult(){
				console.log("====getSearchResult====");
				this.$lobster.lyzmlDLNA.getSearchResult((res)=>{
					console.log(res);
					
					uni.showModal({
						content:JSON.stringify(res)
					})
					this.devList = res.list;
					//console.log("====getSearchResult====",JSON.stringify(devList));
				});
				// lyzmlDLNA.getSearchResult((devList)=>{
				// 	this.devList = devList;
				// 	console.log("====getSearchResult====",JSON.stringify(devList));
				// });
			},
			play(){
				if(this.devList && this.devList.length>0){
					this.$lobster.lyzmlDLNA.playVideo(this.devList[0]);
				}else{
					uni.showToast({
						icon:"none",
						title:"无可用设备"
					});
				}
			},
			playVideo(item){
				console.log("====playVideo====",item);
				let url = "http://v.tiaooo.com/llbizosAzGhJPXC0H4AHLTGHl42W";
				this.$lobster.lyzmlDLNA.playVideo({
					ip:item.ip,
					mediaURL:url
				},(resp)=>{
					uni.showModal({
						content:JSON.stringify(resp)
					})
					console.log("====playVideo=====",resp);
				});
			},
			stopVideo(){
				console.log("====stopVideo====");
				this.$lobster.lyzmlDLNA.stopVideo();
			},
			clearDevice(){
				this.devList = [];
			},
			getIPAddress(){
				this.$lobster.lyzmlDLNA.getIpAddress((ip)=>{
					uni.showToast({
						icon:"none",
						title:"ip:"+ip
					});
					console.log("====getIPAddress====",ip);
				});
			}
		}
	}
</script>

<style>
	.lyzml-btn { 
		width: 688rpx;
		height: 80rpx;
		margin: 20rpx auto;
		border: solid 1px;
		background-color: #4F91E2;
		color: #FFFFFF;
		font-weight: 900;
		text-align: center;
		line-height: 80rpx;
		border-radius: 40rpx;
	}
	.device-item{
		width: 750rpx;
		height:60rpx;
		line-height: 60rpx;
		background-color: #C0C0C0;
		color: #FFFFFF;
		text-align: center;
	}
</style>

